package com.leetcode.partition19;

/**
 * @author `RKC`
 * @date 2021/12/6 9:21
 */
public class LC1816截断句子 {

    public static String truncateSentence(String s, int k) {
        StringBuilder sb = new StringBuilder();
        String[] str = s.split(" ");
        for (int i = 0; i < k; i++) sb.append(str[i]).append(" ");
        sb.deleteCharAt(sb.lastIndexOf(" "));
        return sb.toString();
    }

    public static void main(String[] args) {
        System.out.println(truncateSentence("chopper is not a tanuki", 5));
    }
}
